﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YasharEl.Infrastructure.ApplicationModel.Bootstrap.Extensibility;

namespace YasharEl.Infrastructure.ApplicationModel.Bootstrap.Behavior
{
    /// <summary>
    /// Behavior which disposes all extensions which implement IDisposable
    /// </summary>
    public class DisposeExtensionBehavior : IBehavior<IBootstrappingExtension>
    {
        public string Name
        {
            get
            {
                return this.GetType().FullNameToString();
            }
        }

        /// <summary>
        /// Diposes all extensions which implement IDisposable.
        /// </summary>
        /// <param name="extensions">The extensions.</param>
        public void Behave(IEnumerable<IBootstrappingExtension> extensions)
        {
            foreach (IDisposable extension in extensions.OfType<IDisposable>())
            {
                extension.Dispose();
            }
        }

        public string Describe()
        {
            return "Disposes all extensions which implement IDisposable.";
        }
    }
}
